package daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import Util.DButil;
import pojo.Areas;
import dao.AreasDao;
import factory.DBFactory;

public class AreasDaoImpl implements AreasDao{

	public List<Areas> findByKey(String key) {
		String sql="select * from areas where area like ?";
		List<Areas> list = new ArrayList<Areas>();
		Connection con= null;
		PreparedStatement pst= null;
		ResultSet rs = null;
		try {
			con = DBFactory.getConnection();
			pst = con.prepareStatement(sql);
			pst.setString(1, "%"+key + "%");
			rs= pst.executeQuery();
			while(rs.next()){
				Areas areas = new Areas(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(3));
				list.add(areas);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		DButil.close(con, pst, rs);
		return list;
	}

}
